home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / appsrcs.zip / APPPRINT.ZIP / APPPRINT.OLD < prev    next >
Text File  |  1993-02-13  |  4KB  |  154 lines

  1. /*-------------------------------------------------------------------------
  2.  AppPrint.c
  3.  
  4.  A FilePrint tool for AppBar.
  5.  
  6.  by
  7.  GMP van kempen
  8.  NEVERnever Software 1993
  9.  
  10. ---------------------------------------------------------------------------*/
  11. //compile with the strictest error checking
  12. #define STRICT
  13. #include <windows.h>
  14. #include <windowsx.h>
  15. #include <commdlg.h>
  16. #include <cderr.h>
  17. #include <string.h>
  18. #include <stdio.h>
  19. #include <shellapi.h>
  20. #include <ctl3d.h>
  21. #include "appprint.h"
  22.  
  23. HWND    hWnd;
  24. HINSTANCE hInst;
  25. HICON    hAppPrint;
  26. char szAppName[] = "AppPrint";
  27.  
  28. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  29.            LPSTR lpszCmdLine, int nCmdShow)
  30.     {
  31.     static DLGPROC lpfnPrintDlgProc;
  32.     MSG     msg;
  33.     WNDCLASS    wndclass;
  34.     int     Error;
  35.  
  36.     if(!hPrevInstance)
  37.     {
  38.     wndclass.style            = CS_HREDRAW | CS_VREDRAW;
  39.     wndclass.lpfnWndProc        = WndProc;
  40.     wndclass.cbClsExtra        = 0;
  41.     wndclass.cbWndExtra        = DLGWINDOWEXTRA;
  42.     wndclass.hInstance        = hInstance;
  43.     wndclass.hIcon            = LoadIcon(hInstance, szAppName);
  44.     wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
  45.     wndclass.hbrBackground        = COLOR_WINDOW + 1;
  46.     wndclass.lpszMenuName        = NULL;
  47.     wndclass.lpszClassName        = szAppName;
  48.  
  49.     RegisterClass(&wndclass);
  50.     }
  51.  
  52.     Ctl3dRegister(hInstance);
  53.     Ctl3dAutoSubclass(hInstance);
  54.  
  55.     hWnd = CreateWindow(szAppName, szAppName, WS_POPUP, 0, 0, 1, 1,
  56.             NULL, NULL, hInstance, NULL);
  57.  
  58.     hInst = hInstance;
  59.     hAppPrint = LoadIcon(hInst, szAppName);
  60.  
  61.     if(lstrlen(lpszCmdLine))
  62.     {
  63.     Error = ShellExecute(hWnd, "print", lpszCmdLine, NULL, NULL, NULL);
  64.     if(Error == 31)
  65.        OkMsgBox("AppPrint for AppBar","Could not print.\nNo association found\nfor dropped file.\n");
  66.     SendMessage(hWnd, WM_DESTROY, 0, 0);
  67.     }
  68.     else
  69.     {
  70.     lpfnPrintDlgProc = (DLGPROC) MakeProcInstance((FARPROC)PrintDlgProc, hInst);
  71.     DialogBox(hInst, "PrintDlg", hWnd, lpfnPrintDlgProc);
  72.     FreeProcInstance((FARPROC)lpfnPrintDlgProc);
  73.     SendMessage(hWnd, WM_DESTROY, 0, 0);
  74.     }
  75.  
  76.     while(GetMessage(&msg, NULL, 0, 0))
  77.     {
  78.     TranslateMessage(&msg);
  79.     DispatchMessage(&msg);
  80.     }
  81.  
  82.     Ctl3dUnregister(hInst);
  83.     return msg.wParam;
  84.     } /* end WinMain */
  85.  
  86.  
  87. /*------------------------------------------------------------------------/
  88.    FUNCTION: WndProc()
  89. /------------------------------------------------------------------------*/
  90. long WINAPI WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  91.     {
  92.     return DefWindowProc(hWnd, message, wParam, lParam);
  93.     }
  94.  
  95. /*------------------------------------------------------------------------/
  96.    FUNCTION: PrintDlgProc()
  97. /------------------------------------------------------------------------*/
  98. BOOL WINAPI PrintDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  99.     {
  100.     HDC hDC;
  101.     PAINTSTRUCT ps;
  102.     RECT rc;
  103.     PRINTDLG pd;
  104.     char szPrinter[256];
  105.     char szCurrent[512];
  106.  
  107.     switch(message)
  108.     {
  109.     case WM_INITDIALOG:
  110.         GetProfileString("windows", "device", "<none>", szPrinter, 200);
  111.         strcpy(szCurrent, "current printer: ");
  112.         strcat(szCurrent, szPrinter);
  113.         SetDlgItemText(hDlg, ID_TEXT, "current printer");
  114.         return TRUE;
  115.  
  116.     case WM_PAINT:
  117.         hDC = BeginPaint(hDlg, &ps);
  118.         rc = ps.rcPaint;
  119.         if(IsIconic(hDlg))
  120.         DrawIcon(hDC, 0, 0, hAppPrint);
  121.         EndPaint(hDlg, &ps);
  122.         return 0;
  123.  
  124.     case WM_COMMAND:
  125.         switch(wParam)
  126.         {
  127.         case ID_OK:
  128.             EndDialog(hDlg, 0);
  129.             SendMessage(hWnd, WM_DESTROY, 0, 0);
  130.             return TRUE;
  131.  
  132.         case ID_HELP:
  133.             WinHelp(hDlg,"AppPrint.hlp", HELP_CONTENTS, 0L);
  134.             break;
  135.  
  136.         case ID_PRINT:
  137.             /* Initialize PRINTDLG structure */
  138.             memset(&pd, 0, sizeof(PRINTDLG));
  139.             pd.lStructSize=sizeof(PRINTDLG);
  140.             pd.hwndOwner=hWnd;
  141.             pd.Flags=PD_RETURNIC | PD_PRINTSETUP;
  142.             /* display commondialog Print Dialog */
  143.             PrintDlg(&pd);
  144.  
  145.             GetProfileString("windows", "device", "<none>", szPrinter, 255);
  146.             //vsprintf(szCurrent,"current printer: %s",szPrinter);
  147.             //SetDlgItemText(hDlg, ID_TEXT, szCurrent);
  148.             break;
  149.         }
  150.         break;
  151.     }
  152.     return FALSE;
  153.     } /* end PrintDlgProc */
  154.